﻿using System;
using System.Data;
using System.Windows.Forms;
using Telerik.WinControls.UI;

namespace FSO
{
    public partial class DialogFormSelectObject : Form
    {
        private InterfaceSearchControl _searchControl;

        public DialogFormSelectObject(ObjctTypeEnum type)
            :this(type, null)
        { 
        }

        public DialogFormSelectObject(ObjctTypeEnum type, int? pid)
        {
            InitializeComponent();

            panelSearch.Controls.Clear();

            switch (type)
            {
                case ObjctTypeEnum.INVOICE_IN:             
                    _searchControl = new UserControlSearchInvoiceIn() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.PAYMENT_OUT:
                    _searchControl = new UserControlSearchPayOut() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.CONTRACT:
                    _searchControl = new UserControlSearchContract() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.ORGANIZATION:
                    _searchControl = new UserControlSearchOrganization() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.NSI_MATERIAL:
                    _searchControl = new UserControlSearchMaterial() { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.NSI_PRODUCT:
                    _searchControl = new UserControlSearchNSIProduct() {Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.PRODUCT_UNIT_FOR_COST_PROTOCOL:
                    _searchControl = new UserControlSearchProductUnitForCostProtocol(pid) {Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
				case ObjctTypeEnum.PRODUCT_UNIT_FOR_INVOICE_OUT:
					_searchControl = new UserControlSearchPrUnitForInvoiceOut(pid) { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.PRUDUCT_UNIT_FOR_FORMS:
                    _searchControl = new UserControlSearchPrUnitByID(pid) { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.INVOICE_OUT:
                    _searchControl = new UserControlSearchInvoiceOut(pid) { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.PAYMENT_IN:
                    _searchControl = new UserControlSearchPaymentIn(pid) { Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false }; break;
                case ObjctTypeEnum.NSI_SERVICE:
                    _searchControl = new UserControlSearchNSIService() {Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false}; break;
                case ObjctTypeEnum.VAT_INVOICE:
                    _searchControl = new UserControlSearchVatInvoice(pid) {Dock = DockStyle.Fill, EnableFiltering = true, OpenOnDoubleClick = false}; break;
                default:
                    _searchControl = null;
                    break;
            }
        }

        public GridViewSelectedRowsCollection SelectedRows
        {
            get
            {
                return _searchControl.SelectedRows;
            }
        }

        public DataRow SelectedRow
        {
            get
            {
                return _searchControl.SelectedRow;
            }
        }

        public DataSet OwnerDataSet
        {
            get
            {
                return _searchControl.OwnerDataSet;
            }
        }

        public InterfaceSearchControl Control
        {
            get
            {
                return _searchControl;
            }
        }

        private void DialogFormSelectObject_Load(object sender, EventArgs e)
        {
            if(_searchControl != null)
                panelSearch.Controls.Add((Control) _searchControl);
        }
    }
}
